// Copyright 2010 Abhishek Kulkarni. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"goprop.googlecode.com/hg/goprop"
	"fmt"
)

func main() {

	var barometer *goprop.PropagatorNetwork

	barometer = goprop.NewPropagatorNetwork("barometer")

	t := barometer.NewCell("t")
	g := barometer.NewCell("g")
	one_half := barometer.NewCell("one_half")
	t_2 := barometer.NewCell("t_2")
	gt_2 := barometer.NewCell("gt_2")
	h := barometer.NewCell("h")

	barometer.Constant(goprop.Interval(9.789, 9.832), g)
	barometer.Constant(goprop.Interval(0.5, 0.5), one_half)

	barometer.Quadratic(t, t_2)
	barometer.Product(g, t_2, gt_2)
	barometer.Product(one_half, gt_2, h)

	t.Content(goprop.Interval(2.9, 3.1))

	<- barometer.Quiescent()
	<- barometer.Quiescent()

	fmt.Printf("1: Height of the building is between interval %#v\n", h.Content())

	ratio := barometer.NewCell("ratio")
	h_ba := barometer.NewCell("barometer-height")
	s_ba := barometer.NewCell("barometer-shadow")
	shadow := barometer.NewCell("building-shadow")

	barometer.Product(s_ba, ratio, h_ba)
	barometer.Product(shadow, ratio, h)

	shadow.Content(goprop.Interval(54.9, 55.1))

	h_ba.Content(goprop.Interval(0.3, 0.32))

	s_ba.Content(goprop.Interval(0.36, 0.37))

	// **** Similar triangles method

	fmt.Printf("2: Height of the building is between interval %#v\n", h.Content())

	barometer.Stop()
}
